package com.yanqu.road.server.cmd.activity.crosspasture;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PastureProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.crosspasture.CrossPastureModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_PASTURE_FINISH_GUIDE, desc = "完成引导")
public class PastureFinishGuideCmd extends AbstractCommand {

    private boolean finishGuide;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PastureProto.PastureFinishGuideReqMsg reqMsg = PastureProto.PastureFinishGuideReqMsg.parseFrom(packet.getBytes());
        finishGuide = reqMsg.getFinishGuild();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(CrossPastureModule.class).finishGuide(finishGuide);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            PastureProto.PastureFinishGuideRespMsg.Builder respMsg = PastureProto.PastureFinishGuideRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_CROSS_PASTURE_FINISH_GUIDE, respMsg);
        }
    }
}
